package com.example.epoxystudy.views;

import android.content.Context;
import android.net.Uri;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.airbnb.epoxy.ModelProp;
import com.airbnb.epoxy.ModelView;
import com.example.epoxystudy.R;
import com.example.epoxystudy.Utils;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.Locale;

import timber.log.Timber;

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_MATCH_HEIGHT)
public class PageItemView extends FrameLayout {

    SimpleDraweeView mImage;
    TextView mPage;

    public PageItemView(Context context) {
        super(context);
        init();
    }

    private void init() {
        inflate(getContext(), R.layout.item_page, this);
        mImage = findViewById(R.id.iv_image);
        mPage = findViewById(R.id.tv_page);
        ViewGroup.LayoutParams imgParams = mImage.getLayoutParams();
        imgParams.width = getResources().getDisplayMetrics().widthPixels;
        imgParams.height = getResources().getDisplayMetrics().heightPixels;
    }

    @ModelProp
    public void setImage(String thumb) {
        Timber.d(Utils.format("setImage %s ", thumb));
        Uri uri = Uri.parse(thumb);
        mImage.setImageURI(uri);
    }

    @ModelProp
    public void setPage(Integer page) {
        mPage.setText(String.format(Locale.CHINA, "%d", page));
        Timber.d(Utils.format("setPage %d ", page));
    }
}
